package com.example.smart.handler;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;
@Component
public class LogoutSuccessHandlers implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        System.out.println("退出登录成功后的处理");
        // 销毁会话，清空缓存等。
        request.getSession().invalidate(); // 销毁会话
        authentication.setAuthenticated(false); // 设置未登录状态
        response.sendRedirect("/login"); // 重定向
    }
}
